package com.huonan.component.tmp.filter;

import com.huonan.component.tmp.RegularUtil;
import com.huonan.component.tmp.vo.ExtractRegularInfo;
import com.huonan.component.tmp.vo.UserLanguageTextVo;
import com.mininglamp.bia.emojiextractor.EmojiExtractor;
import com.mininglamp.bia.emojiextractor.PlatformEnum;

import java.util.List;

/**
 * 处理文本基础类
 */
public abstract class UserTextFilter {


    /**
     * 过滤标签
     *
     * @param text 文本内容
     * @return 处理后的文本内容
     */
    protected abstract UserLanguageTextVo filter(String text);

    abstract void formatTags(UserLanguageTextVo userLanguageTextVo);

    UserLanguageTextVo doFilter(PlatformEnum source, String text,
                                ExtractRegularInfo regularInfo) {
        UserLanguageTextVo userLanguageTextVo = new UserLanguageTextVo();

        userLanguageTextVo.setAfterText(text);
        RegularUtil.extractAndRemoveMatches(userLanguageTextVo, regularInfo.getForwardReg(),
                userLanguageTextVo::setForwardList);
        RegularUtil.extractAndRemoveMatches(userLanguageTextVo, regularInfo.getNickNameReg(),
                userLanguageTextVo::setNickNameList);
        RegularUtil.extractAndRemoveMatches(userLanguageTextVo, regularInfo.getTopicReg(),
                userLanguageTextVo::setTopicList);
        RegularUtil.extractAndRemoveMatches(userLanguageTextVo, regularInfo.getOtherReg(),
                userLanguageTextVo::setOtherList);

        List<String> emojiList = EmojiExtractor.extractEmoji(userLanguageTextVo.getAfterText());
        List<String> expressionList = EmojiExtractor.extractPlatformExpression(source, userLanguageTextVo.getAfterText());
        userLanguageTextVo.setExpressionList(expressionList);
        userLanguageTextVo.setEmojiList(emojiList);

        emojiList.addAll(expressionList);
        RegularUtil.rmMatche(emojiList, userLanguageTextVo);
        return userLanguageTextVo;
    }

}
